package com.test.mchelepesa.dialog_rice;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;

import androidx.annotation.NonNull;

import com.test.mchelepesa.R;
import com.test.mchelepesa.util_rice.http_rice.HttpManager_rice;

public class SmsStatementDialog_rice extends Dialog {

    private final Runnable onDeny;
    private final Runnable onAgree;

    public SmsStatementDialog_rice(@NonNull Context context, Runnable onDeny, Runnable onAgree) {
        super(context);
        this.onDeny = onDeny;
        this.onAgree = onAgree;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_sms_statement_rice);

        getWindow().setBackgroundDrawableResource(R.color.trans);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

//        findViewById(R.id.sms_ib_close).setOnClickListener(view -> {
//            HttpManager_rice.getInstance().saveUserBuriedPoint("DIALOG_SMS_CLOSE_CLICK");
//            dismiss();
//        });

        CheckBox readCb = findViewById(R.id.sms_cb_read_tips);
        Button denyBtn = findViewById(R.id.sms_btn_deny);
        Button agreeBtn = findViewById(R.id.sms_btn_agree);

        denyBtn.setOnClickListener(view -> {
            HttpManager_rice.getInstance().saveUserBuriedPoint("DIALOG_SMS_DENY_CLICK");
            if (onDeny!=null) onDeny.run();
        });

        agreeBtn.setOnClickListener(view -> {
            HttpManager_rice.getInstance().saveUserBuriedPoint("DIALOG_SMS_AGREE_CLICK");

            if (readCb.isChecked()) {
                if (onAgree!=null) onAgree.run();
            } else {
                new TipsDialog_rice(getContext(),() -> {
                    readCb.setChecked(true);
                    if (onAgree!=null) onAgree.run();
                }).show();
            }

        });

    }

}
